<template>
  <view class="three-order">
    <view class="total">
      <view class="unpayment">
        <view class="total-title">未支付金额</view>
        <view class="total-amount">{{ unitVal(details.unpayTotalAmount) }}</view>
      </view>
      <ve-line direction="col" color="#F1F1F1" length="72" />
      <view class="payment">
        <view class="total-title">已支付金额</view>
        <view class="total-amount">{{ unitVal(details.payedTotalAmount) }}</view>
      </view>
    </view>

    <ve-card
      v-for="item in details.data"
      :key="item.siteId"
      :title="`账单金额：${unitVal(item.totalAmount)}`"
      :sub-title="item.payStatusName"
      :type="payCardType(item)"
      :fold="true"
      v-model:initFold="item.initExpand"
    >
      <ve-cell label="费用明细" layout="vertical">
        <template v-if="item.feeList.length > 0">
          <view class="cost-box">
            <view class="cost-item" v-for="list in item.feeList" :key="list.id">
              <view class="cost-title"> {{ list.feeName }} </view>
              <view class="cost-num">{{ unitVal(list.feeActiveAmount) }}</view>
            </view>
          </view>
        </template>
        <template v-else> - </template>
      </ve-cell>
      <ve-cell label="收款类型">{{ item.costTypeName || '-' }}</ve-cell>
      <ve-cell label="收支方式">
        <view>
          {{ item.payTypeName || '-' }}
          <view v-if="item.payType == -1"> {{ item.settlementBodyName }}</view>
        </view>
      </ve-cell>
      <ve-cell label="交易完成时间">{{ item.finishTime || '-' }}</ve-cell>
      <ve-cell label="客户名称">{{ item.customerName || '-' }}</ve-cell>
      <ve-cell label="费用备注">{{ item.remark || '-' }}</ve-cell>
      <ve-cell label="账单号">
        <view style="width: 100%">
          <view> {{ item.billCode }} </view>
          <view class="out-order">
            <ve-tag color="blue" title="外部" style="width: 40px; margin-right: 4px" />
            <view class="text">
              <text class="ellipsis">{{ item.outBillCode || '-' }}</text>
            </view>
          </view>
        </view>
      </ve-cell>
      <ve-cell label="操作人">{{ item.createUserName || '-' }}</ve-cell>
      <ve-cell label="生成时间">{{ item.createTime || '-' }}</ve-cell>
    </ve-card>
  </view>
</template>

<script setup lang="ts">
  import { unitVal } from '@/utils'

  const props = defineProps({
    details: {
      type: Object,
      default: () => ({}),
    },
  })

  const payCardType = (options: any) => {
    switch (
      options.payStatus // 0: 未支付 1: 已支付 9: 已取消
    ) {
      case 0:
        return 'yellow'
      case 1:
        return 'blue'
      case 9:
        return 'gray'
    }
  }
</script>

<style lang="less" scoped>
  .three-order {
    .total {
      height: 136rpx;
      display: flex;
      justify-content: space-evenly;
      align-items: center;
      background-color: #fff;
      font-weight: 400;
      font-size: 14px;
      color: #4e5969;
      margin-bottom: 24rpx;

      .total-amount {
        color: #3072f6;
      }
    }
  }

  .cost-box {
    font-weight: 400;
    font-size: 15px;
    color: #8491a8;
    background: #f7f8fa;
    padding: 24rpx 24rpx;

    .cost-item {
      display: flex;
      align-items: center;
      margin-bottom: 4px;

      &:last-child {
        margin-bottom: 0;
      }

      .cost-title {
        min-width: 120px;
        padding-right: 16px;
      }

      .cost-num {
        font-size: 14px;
        color: #191c27;
        text-align: right;
        min-width: 100px;
      }
    }
  }

  .title-box {
    display: flex;
    flex-direction: column;
    width: 450rpx;
    font-weight: 400;
    font-size: 12px;
    color: #8491a8;

    .title-item {
      display: flex;
      .title-label {
        display: flex;
        justify-content: flex-end;
        width: 26%;
        margin-right: 5px;
      }
      .title-value {
        width: 73%;
        text-align: left;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }

  .out-order {
    display: flex;
    align-items: center;

    .text {
      flex: 1;
    }
  }
</style>
